# Bug Fixing for Everybody

## (even non-programmers)

## The Handout

Rule 0: DON'T PANIC

Code is just text.

Mystery: Who, What, When, Where, Why
Where matters most; What is second

Scripts

- Don't need to be compiled
- Firefox, GIMP, OpenOffice, boot/hotplug scripts
- Standalone scripts in /usr/bin, /usr games etc.

grep: search for patterns in files

      grep pattern file1 file2 file3 ...

Useful grep flags

- grep -i: ignore case
- grep -v: everything but the pattern
- grep -r: recursive (search subdirectories)
  grep -r pattern .

file: find out the type of a file

      file file1 file2 file3 ...

Shell pipelines
pass output from one program into the input of another

    file /usr/bin/* | grep script

Personal bin directory: $HOME/bin
Add to .bashrc: export PATH=$HOME/bin:$PATH
Then you can run anything in your personal bin just by typing it.
Make sure files there are executable: chmod ugo+x filename

Text editors:

- Use whatever you're comfortable with as long as it's not a word processor (just plain text).
- Be comfortable with search.
- Other nice bells & whistles: syntax highlighting, parentheses matching. (That's why programmers like emacs and vim.)

## Sample fixes:

### wargames

/usr/games/wargames (sh script)
Make a copy, e.g. in your personal bin.
Add

      ls /usr/games

in the "else" clause.
Also add ", $x" to print out the name of the game you requested.

### GIMP

GIMP: (C)
Turn on Preview checkbox in Save as JPEG dialog, always.

#### Building C programs:

From Debian/Ubuntu:

    apt-get source gimp
    apt-get build-dep gimp
    cd gimp
    dpkg-buildpkg

From tarball:

    tar xvf gimp-2.6.5.tar.bz2
    cd gimp-2.6.5
    ./configure
    make

Optional step (might not want to do it when testing):

    sudo make install

If you don't do `make install`, find runnable program with:

    find . -name "*gimp*"

(or whatever the program name).

Special hint for gimp: if you're building a different version than the one installed with your system, add this to configure:

    ./configure --prefix=/usr/local/gimp-2.6

That helps the two versions coexist. See the README for more info.

Search for the right file:

    $ grep -r "preview in image window" .
    $ grep -r "preview in image" . | grep -v po

Edit plug-ins/jpeg/jpeg-save.c
Search for 'preview in image'
Find it in gtk_check_button_new_with_mnemonic
Next line: gtk_toggle_button_set_active
Google for gtk_toggle_button_set_active documentation
First hit: GNOME Documentation Library: verifies that gtk_toggle_button_set_active turns the checkbox on/off
Change

      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (toggle), jsvals.preview);

to

      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (toggle), TRUE);

## Crashes:

Have a core? gdb `which program-name` core No core? gdb `which program-name` then type: run

## Search the bug system.

Use it like a google search: don't worry about those other fields.

Describe the bug

- What triggers it? When does it happen?
- How can you or someone else reproduce it?
- Include as much information as you can: version, OS/distro, and exactly what you do to trigger it.

## Patches

Apply an existing patch: patch [-pN] < patchfile Make a patch: diff -c file.sav file.new >mypatch.diff

## Finding bugs to fix:

Bugzilla keywords

- helpwanted (Mozilla),
- gnome-love (Gnome) http://live.gnome.org/GnomeLove